      SUBROUTINE ACCOMP
C
      IMPLICIT REAL*8 (A-H,O-Z)
      REAL*8 J2,J3,J4,J22
C
C    SUBROUTINE ACCOMP SERVES THE PURPOSE OF COMPUTING
C   ACCELERATION VECTOR OF UP TO SIX POINTS ON THE HUB,
C   AND ON THE BOOM TIP.  THE COMMUNICATION ARE VIA COMMON BLOCKS
C
C
C   THE OLD COMMON BLOCKS TO BE USED IN THIS ROUTINE
C
      COMMON/CONSTS/PI,TWOPI,RADIAN
C
      COMMON/CANTNA/ A(10,3),ADOT(10,3),B(10,3),BDOT(10,3),DIN(10,3),
     .               DINDOT(10,3),DOUT(10,3),DOUTDT(10,3)
C
      COMMON/CNBODY/J2,J3,J4,J22,ZJ20,ZMU,WWO ,FLAT,AEARTH
C
C
      COMMON/DEBUG2/ IOUT,JOUT,KLUGE
C
      COMMON/IPOOL1/ IGRAV,IDAMP,IK,K1,ITIM,IAB,IAPS,IBB,IBPS,
     *NK(10),LK(10),LLK(10)
C
      COMMON/LIBDPR/ZK1D,ZK2D,PHIS,PHILD,DPHILD,BETLD,GAMLD,
     *      ZMDO,ZMDBO,CNV,DECAY
C
      COMMON/MRANG/ ADDOT(10,3),BDDOT(10,3),DOUTDD(10,3),DINDD(10,3)
C
      COMMON/RPOOL1/ RHOK(10),TIME,SA(3,3),FM1(3,3),ZLK(10),
     1OMEG(3),ZLKP(10),ZLKDP(10),CMAT(3,3),
     2 GBAR(3,3),YBCM(3),ZBZK(3,10),FCM(3,3),DTO,PHID,PHI
C
      COMMON/RPOOL3/ZMS,YIZM(3,2)
C
      COMMON/RPOOL5/ CKMAT(3,3,10),FM2(3,3)
C
      COMMON/RPOOL6/FM(3,3),CIY(3,3),CIZ(3,3),SAT(3,3),SZ1,SZ2,SZ3
C
      COMMON/VARBLS/ DEPEND(150),DERIV(150)
C
      COMMON/VECTRS/ XSAT(3),XSATDT(3),AD(3)
C
C   COMMON BLOCKS FROM THE THRUSTING ROUTINES
C
C
      COMMON/ITCNTL/ IPULSE,ISPLSE,KPULSE,ITSW,IOTSW
C
      COMMON/THRUST/TV(3),TL(3),TT(4),TPAR(4),REF
C
      COMMON/TIMPLS/ TMEAN,TPULSE,TOPLSE,TTSTOP,DELV
C
      COMMON/CSTVAL/TSTART,ZL0(10),ZL1(10),ZL2(10),ZLA(10)
C
C   THE FOLLOWING ARE NEW COMMON BLOCKS ASSOCIATED WITH
C   THE INPUTS AND OUTPUTS OF THE ACCELERATION COMPUTATIONS
C
      COMMON/ACCHUB/ YHUB(3,6),HUBACC(3,6),ACCRED(6),ALFAEA(6),
     .  BETAEA(6),GAMAEA(6),DKAT(3,3,6)
C
      COMMON/ACCORB/ ACCOB(3),TRTACC(3),VCF(3)
C
      COMMON/NUMACC/NY
C
      COMMON/SEPACC/ CENACC(3,10),CORACC(3,10),DLIACC(3,10),TOTACC(3,10)
      COMMON/IACC/ IACOMP,IHUBAC,ITIPAC,IAFLAG
C
C
      COMMON/SHAPES/ ZXI(10,3),ZXIP(10,3),ZXIPP(10,3),ZZNP(10,3,3)
C
C
C    DIMENSIONAL VARIABLES TO BE USED INTERNALLY IN THE ROUTINE
      DIMENSION BOMEG(3,3),OMEGDT(3),BOMGDT(3,3)
      DIMENSION WDAM(3,3), WDAMD(3,3), BOMEG2(3,3)
      DIMENSION OMGRTS(3,3),CAOMG(3,3),WDAM2(3,3)
C
      DIMENSION AA(3),BB(3),AAD(3),BBD(3),AADD(3),BBDD(3),
     1XSH(3),XSHP(3),XSHPP(3),ZNP(3,3),YM(3),CKAT(3,3),ZB(3)
      DIMENSION XAI(3),XAID(3),XAIDD(3)
      DIMENSION DUM1(3),DUM2(3),DUM3(3),DUM4(3),DUM5(3)
      DIMENSION DDAT(3,3),ARES(3,3),DMY(3,3)
C
      DATA JJ/1/
CC
C   TO CONSTRUCT THE ACCELEROMETER LOCATION AND ORIENTATION MATRIX
C
      IF(JJ.EQ.99) GO TO 5
      DO 2 K=1,NY
      CAL=DCOS(ALFAEA(K)*RADIAN)
      SAL=DSIN(ALFAEA(K)*RADIAN)
      CBE=DCOS(BETAEA(K)*RADIAN)
      SBE=DSIN(BETAEA(K)*RADIAN)
      CGA=DCOS(GAMAEA(K)*RADIAN)
      SGA=DSIN(GAMAEA(K)*RADIAN)
      DKAT(1,1,K)=CGA*CBE+SAL*SGA*SBE
      DKAT(1,2,K)=SGA*CAL
      DKAT(1,3,K)=SGA*SAL*CBE-SBE*CGA
      DKAT(2,1,K)=CGA*SAL*SBE-SGA*CBE
      DKAT(2,2,K)=CAL*CGA
      DKAT(2,3,K)=CGA*SAL*CBE+SBE*SGA
      DKAT(3,1,K)=CAL*SBE
      DKAT(3,2,K)=-SAL
      DKAT(3,3,K)=CAL*CBE
C
C   THE MATRIX DKAT IS ACTUALLY THE INVERSE OF THE MATRIX FROM
C   BODY TO ELEMENT FRAMES
C
 2    CONTINUE
      JJ=99
 5    CONTINUE
C   CONSTRUCT THE REQUIRED QUANTITIES FOR COMPUTATION
C
C
C   TO CONSTRUCT THE BODY INERTIAL RATE SKEW SYMMETRICAL MATRIX
C
      DO 10 I=1,3
      DO 10 J=1,3
 10   BOMEG(I,J)=0.0D0
      BOMEG(1,2)=-OMEG(3)
      BOMEG(1,3)=OMEG(2)
      BOMEG(2,1)=OMEG(3)
      BOMEG(2,3)=-OMEG(1)
      BOMEG(3,1)=-OMEG(2)
      BOMEG(3,2)=OMEG(1)
C
C   CONSTRUCT THE RATE MATRIX OF BOMEG
C
C   TO OBTAIN OMEGDOT
C
      OMEGDT(1)=DERIV(7)
      OMEGDT(2)=DERIV(8)
      OMEGDT(3)=DERIV(9)
      DO 30 I=1,3
      DO 30 J=1,3
 30   BOMGDT(I,J)=0.0D0
      BOMGDT(1,2)=-OMEGDT(3)
      BOMGDT(1,3)=OMEGDT(2)
      BOMGDT(2,1)=OMEGDT(3)
      BOMGDT(2,3)=-OMEGDT(1)
      BOMGDT(3,1)=-OMEGDT(2)
      BOMGDT(3,2)=OMEGDT(1)
C
C   CONSTRUCT THE DAMPER FRAME RATE MATRIX
C
      DO 40 I=1,3
      DO 40 J=1,3
      WDAM(I,J)=0.0D0
 40   WDAMD(I,J)=0.0D0
      IF(IDAMP.EQ.0) GO TO 50
      BED=BETLD*RADIAN
      GMD=GAMLD*RADIAN
      SBED=DSIN(BED)
      CBED=DCOS(BED)
      SGMD=DSIN(GMD)
      CGMD=DCOS(GMD)
C
C   THE DAMPER FRAME RATE SKEW SYMMETRICAL MATRIX
C
      WDAM(1,2)=-PHID*SGMD*SBED
      WDAM(1,3)=PHID*CGMD
      WDAM(2,1)=-WDAM(1,2)
      WDAM(2,3)=PHID*SGMD*CBED
      WDAM(3,1)=-WDAM(1,3)
      WDAM(3,2)=-WDAM(2,3)
C
C   THE RATE MATRIX OF WDAM
C
C   THE RATE OF PHID
C
      PHIDD=DERIV(11)
      WDAMD(1,2)=-PHIDD*SGMD
      WDAMD(1,3)=PHIDD*CGMD
      WDAMD(2,1)=-WDAMD(1,2)
      WDAMD(2,3)=PHIDD*SGMD*CBED
      WDAMD(3,1)=-WDAMD(1,3)
      WDAMD(3,2)=-WDAMD(2,3)
C
C   END THE CONSTRUCTION OF DAMPER PROPERTIES
 50   CONTINUE
C
C   START THE COMPUTATION OF ACCLERATION VECTOR
C
C   COMPUTE THE TWO BODY ORBIT INERTIAL ACCLRATION
C
      RADIUS=0.0D0
      DO 60 I=1,3
 60   RADIUS=RADIUS+XSAT(I)*XSAT(I)
      RADIUS=DSQRT(RADIUS)
      DO 70 I=1,3
 70   ACCOB(I)=-(ZMU*XSAT(I))/(RADIUS**3)
C
C   CONVERT THE ORBIT ACCELERATION FROM KM/SEC 2 TO FT/SEC 2
C
      DO 80 I=1,3
 80   ACCOB(I)=ACCOB(I)*3280.8D0
C
C   END THE ORBIT ACCELERATION COMPUTATION
C
C   START THE COMPUTATION OF ACCELERATION ON THE HUB
C
C     IF(IHUBAC.EQ.0) GO TO 100
      CALL MATMPY(BOMEG,BOMEG,BOMEG2,3,3)
      DO 90 I=1,3
      DO 90 J=1,3
      OMGRTS(I,J)=BOMGDT(I,J)+BOMEG2(I,J)
 90   CONTINUE
      CALL MATMPY(SA,OMGRTS,CAOMG,3,3)
C
      DO 100 K=1,NY
      DO 110 I=1,3
 110  HUBACC(I,K)=0.0D0
      DO 120 II=1,3
      DO 120 J=1,3
      HUBACC(II,K)=HUBACC(II,K)+CAOMG(II,J)*YHUB(J,K)
 120  CONTINUE
C
 100  CONTINUE
C
C   END OF THE HUB ACCELERATION COMPUTATION
C
C   START THE BOOM TIP ACCELERATION COMPUTATION
C
C   ZEROED THE ARRAYS
C
C     IF(ITIPAC.EQ.0) GO TO 150
      DO 130 I=1,3
      AA(I)=0.0D0
      BB(I)=0.0D0
      AAD(I)=0.0D0
      BBD(I)=0.0D0
      AADD(I)=0.0D0
      BBDD(I)=0.0D0
      XSH(I)=0.0D0
      XSHP(I)=0.0D0
      XSHPP(I)=0.0D0
      DO 140 J=1,3
 140  ZNP(I,J)=0.0D0
 130  CONTINUE
C
C   RECEIVE THE TIP DEFLECTION INFORMATIONS
C
C   OBTAIN VALUES FOR EACH ELEMENT
C
      DO 150 K=1,IK
C   OBTAIN THE BOOM LENGTH, DEPLOYMENT RATE AND ACCELERATION
C
      ZLL=ZL0(K)
      ZLD=ZL1(K)
      ZLDD=ZLA(K)
C
      IF(NK(K).NE.0) GO TO 155
      XAI(1)=ZLL
      XAI(2)=0.0D0
      XAI(3)=0.0D0
      XAID(1)=ZLD
      XAID(2)=0.0D0
      XAID(3)=0.0D0
      XAIDD(1)=ZLDD
      XAIDD(2)=0.0D0
      XAIDD(3)=0.0D0
      GO TO 215
 155  CONTINUE
      MODD=NK(K)
      DO 160 J=1,MODD
      AA(J)=A(K,J)
      BB(J)=B(K,J)
      AAD(J)=ADOT(K,J)
      BBD(J)=BDOT(K,J)
      AADD(J)=ADDOT(K,J)
      BBDD(J)=BDDOT(K,J)
      XSH(J)=ZXI(K,J)
      XSHP(J)=ZXIP(K,J)
      XSHPP(J)=ZXIPP(K,J)
      DO 165 I=1,MODD
 165  ZNP(J,I)=ZZNP(K,J,I)
 160  CONTINUE
C
C   CALL SUBROUTINE TIPVEC TO OBTAIN XAI,XAID,XAIDD
C   FOR EACH ELEMENT. THOSE ARE THE POSITION ,VELOCITY
C   AND ACCELERATION VECTORS OF THE BOOM TIP
C   UN ELEMENT FRAME
C
      CALL TIPVEC(      ZLL,ZLD,ZLDD,AA,BB,AAD,BBD,AADD,BBDD,
     *XSH,XSHP,XSHPP,ZNP,XAI,XAID,XAIDD)
C
 215  CONTINUE
C   CONVERT CKMAT MATRIX INTO THE ELEMENT FRAME
C
      DO 170 I=1,3
      DO 170 J=1,3
 170  CKAT(I,J)=CKMAT(I,J,K)
C
C   DAMPER FRAME ORIGIN
C
      DO 180 I=1,3
 180  YM(I)=0.0D0
      IF(IDAMP.EQ.0) GO TO 190
      DO 200 I=1,3
      YM(I)=YIZM(I,1)
 200  CONTINUE
 190  CONTINUE
C
C   ELEMENT FRAME ORIGIN
C
      DO 210 I=1,3
 210  ZB(I)=ZBZK(I,K)
C
C   START COMPUTING ACCELERATION VECTORS
C
C   COMPUTE CENTRIFIGAL ACCELERATION
C
      DO 220 I=1,3
      DUM1(I)=0.0D0
      DUM2(I)=0.0D0
      DUM3(I)=0.0D0
      DUM4(I)=0.0D0
      DUM5(I)=0.0D0
 220  CONTINUE
      CALL DMATVC(CKAT,XAI,DUM1)
      DO 230 I=1,3
 230  DUM1(I)=DUM1(I)+ZB(I)
      CALL DMATVC(FM,DUM1,DUM2)
      DO 240 I=1,3
 240  DUM2(I)=DUM2(I)+YM(I)
      CALL DMATVC(CAOMG,DUM2,DUM3)
      DO 250 I=1,3
 250  CENACC(I,K)=DUM3(I)
C
C   END THE CENTRIFUGAL ACCELERATION COMPUTATION
C
C   COMPUTE CORIOLIS ACCELERATION
C
      CALL DMATVC(CKAT,XAID,DUM4)
      CALL DMATVC(FM,DUM4,DUM3)
      CALL DMATVC(WDAM,DUM1,DUM2)
      CALL DMATVC(FM,DUM2,DUM5)
      DO 260 I=1,3
 260  DUM4(I)=DUM3(I)+DUM5(I)
      CALL DMATVC(BOMEG,DUM4,DUM2)
      CALL DMATVC(SA,DUM2,DUM3)
      DO 270 I=1,3
 270  CORACC(I,K)=2.0D0*DUM3(I)
C
C   END THE COMPUTATION OF CORIOLIS ACCELERATION
C
C   START LINEAR ACCELERATION COMPUTATION
C
      CALL MATMPY(WDAM,WDAM,WDAM2,3,3)
      DO 280 I=1,3
      DO 280 J=1,3
 280  OMGRTS(I,J)=WDAM2(I,J)+WDAMD(I,J)
      CALL DMATVC(OMGRTS,DUM1,DUM2)
      CALL DMATVC(FM,DUM2,DUM3)
C
      CALL DMATVC(CKAT,XAID,DUM1)
      CALL DMATVC(WDAM,DUM1,DUM2)
      CALL DMATVC(FM,DUM2,DUM4)
      DO 290 I=1,3
 290  DUM4(I)=2.0D0*DUM4(I)
C
      CALL DMATVC(CKAT,XAIDD,DUM1)
      CALL DMATVC(FM,DUM1,DUM5)
      DO 300 I=1,3
 300  DUM1(I)=DUM3(I)+DUM4(I)+DUM5(I)
      CALL DMATVC(SA,DUM1,DUM3)
      DO 310 I=1,3
 310  DLIACC(I,K)=DUM3(I)
C
C   END OF LINEAR ACCELERATION COMPUTATION
C
C   COMPUTE THE TOTAL ACCELERATION EXCEPT THE ORBIT
C
      DO 320 I=1,3
 320  TOTACC(I,K)=CENACC(I,K)+CORACC(I,K)+DLIACC(I,K)
C
 150  CONTINUE
C
C   END THE ACCELERATION COMPUTATION FOR BOOM TIPS
C
C   COMPUTE THE ACCELERATION DUE TO THE THRUSTING
C
      DO 370 I=1,3
 370  DUM1(I)=VCF(I)/ZMS
      CALL DMATVC(SA,DUM1,TRTACC)
      IF(IPULSE.NE.0) GO TO 372
      DO 372 I=1,3
      TRTACC(I)=0.0D0
 372  CONTINUE
C
C   END THE COMPUTATION OF THRUSTING
C
C
C   ADDING THRUSTING ACCELERATION TO THE HUB ELEMENT
C
C     IF(IHUBAC.EQ.0) GO TO 395
      DO 390 K=1,NY
      DO 391 I=1,3
      HUBACC(I,K)=HUBACC(I,K)+TRTACC(I)
      DO 391 J=1,3
 391  DDAT(I,J)=DKAT(I,J,K)
      CALL MPYMAT(DDAT,SA,DMY,1,2,ARES,DMY)
      ACCRED(K)=ARES(1,1)*HUBACC(1,K)+ARES(1,2)*HUBACC(2,K)
     .   +ARES(1,3)*HUBACC(3,K)
 390  CONTINUE
C
 395  CONTINUE
C
C   ADDING THRUSTING TO THE BOOM TIP
C     IF(ITIPAC.EQ.0) GO TO 380
      DO 400 K=1,IK
      DO 400 I=1,3
 400  TOTACC(I,K)=TOTACC(I,K)+TRTACC(I)
C
 380  CONTINUE
C
C   END THE COMPUTATION OF ALL ACCELERATION
C
C   DEBUG MESSAGE FOR  ACCELERATION ROUTINE
C
      IF(IOUT.EQ.1) GO TO 410
      WRITE(6,1000)
 1000 FORMAT('      MESSAGE FROM ACCOMP')
      WRITE(6,1110) (ACCOB(I),I=1,3),RADIUS,ZMU
 1110 FORMAT(' ORBIT ',5(E18.10,2X))
      WRITE(6,1100)
 1100 FORMAT('   BOMEG MATRIX')
 1200 FORMAT(' ',2X,1P9E14.6//)
      WRITE(6,1200) ((BOMEG(I,J),J=1,3),I=1,3)
      WRITE(6,1300)
 1300 FORMAT('   BOMGDT MATRIX')
      WRITE(6,1200) ((BOMGDT(I,J),J=1,3),I=1,3)
      WRITE(6,1400)
 1400 FORMAT('   WDAM MATRIX')
      WRITE(6,1200) ((WDAM(I,J),J=1,3),I=1,3)
      WRITE(6,1500)
 1500 FORMAT(' WDAM MATRIX ')
      WRITE(6,1200)((WDAMD(I,J),J=1,3),I=1,3)
      WRITE(6,1600)
 1600 FORMAT('   CAOMG MATRIX')
      WRITE(6,1200) ((CAOMG(I,J),J=1,3),I=1,3)
      DO 420 K=1,NY
      WRITE(6,1700) K
 1700 FORMAT(' INFORMATIONS IN HUB ELEMENT ',I2)
      WRITE(6,1750) ((DKAT(I,J,K),J=1,3),I=1,3)
 1750 FORMAT(' DKAT',2X,1P9E14.6//)
      WRITE(6,1800) (HUBACC(I,K),I=1,3)
 1800 FORMAT('  HUBACC=',2X,1P3E14.6//)
 420  CONTINUE
      DO 430 K=1,IK
      WRITE(6,1900) K
 1900 FORMAT(' INFORMATIONS FOR BOOM TIP ELEMENT ',I2)
      WRITE(6,1200) ((CKMAT(I,J,K),J=1,3),I=1,3)
      WRITE(6,1200) ((FM(I,J),J=1,3),I=1,3)
      WRITE(6,2000) (YM(I),I=1,3)
 2000 FORMAT(' YM ',2X,1P3E14.6//)
      WRITE(6,2100) (ZBZK(I,K),I=1,3)
 2100 FORMAT(' ZB ',2X,1P3E14.6//)
      WRITE(6,2200) (CENACC(I,K),I=1,3)
 2200 FORMAT(' CENACC ',2X,1P3E14.6//)
      WRITE(6,2300) (CORACC(I,K),I=1,3)
 2300 FORMAT(' CORACC ',2X,1P3E14.6//)
      WRITE(6,2400) (DLIACC(I,K),I=1,3)
 2400 FORMAT(' DLIACC ',2X,1P3E14.6//)
      WRITE(6,2500) (TOTACC(I,K),I=1,3)
 2500 FORMAT(' TOTACC ',2X,1P3E14.6//)
C
 430  CONTINUE
      WRITE(6,2600)
 2600 FORMAT(' ACCELERATION DUE TO THRUSTING')
      WRITE(6,2700) (TRTACC(I),I=1,3)
 2700 FORMAT(' ',2X,1P3E14.6//)
C
 410  CONTINUE
      IF(IACOMP.EQ.0) IAFLAG=0
      RETURN
      END
